package com.content.controller;

import com.content.model.dto.AssociationMediaDto;
import com.content.model.dto.SaveTeachplanDto;
import com.content.model.dto.TeachPlanTreeDto;
import com.content.service.TeachPlanService;
import com.sun.nio.sctp.Association;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "课程计划接口")
@RequestMapping("/teachplan")
@RestController
public class TeachPlanController {
    @Autowired
    private TeachPlanService teachPlanService;

    /**
     * 课程计划查询接口
     *
     * @param courseId
     * @return
     */

    @ApiOperation("课程计划查询接口")
    @GetMapping("/{courseId}/tree-nodes")
    public List<TeachPlanTreeDto> getTeachPlanTree(@PathVariable Long courseId) {
        return teachPlanService.getTeachPlanByCourseId(courseId);
    }


    @ApiOperation("新增和修改课程计划")
    @PostMapping
    public void saveTeachPlan(@RequestBody SaveTeachplanDto saveTeachplanDto) {
        teachPlanService.saveTeachPlan(saveTeachplanDto);
    }

    @ApiOperation("课程计划下移")
    @PostMapping("/movedown/{id}")
    public void moveDown(@PathVariable Long id) {
        teachPlanService.moveDown(id);
    }

    @ApiOperation("课程计划上移")
    @PostMapping("/moveup/{id}")
    public void moveUp(@PathVariable Long id) {
        teachPlanService.moveUp(id);
    }

    @ApiOperation("删除课程计划")
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        teachPlanService.deleteById(id);
    }

    @ApiOperation("删除课程计划媒资")
    @DeleteMapping("association/media/{teachPlanId}/{mediaId}")
    public void deleteMedia(@PathVariable Long teachPlanId, @PathVariable String mediaId) {
        teachPlanService.deleteMedia(teachPlanId, mediaId);
    }

    @ApiOperation("绑定媒资信息")
    @PostMapping("/association/media")
    public void associationMedia(@RequestBody AssociationMediaDto associationMediaDto) {
        teachPlanService.associationMedia(associationMediaDto);
    }
}
